/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modulo4;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import java.io.PrintWriter;
import Modelo.DAL.ConexionBD;
import Modelo.DAL.ObjetoPerdido_DAO;
import Acceso.Security;
import Modelo.ObjetoPerdido;
import java.sql.*;
import java.util.List;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author dayana
 */
public class eliminarObjetoPerdidoAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        String[] a = {"Administrador","Director DSI","Jefe Apoyo Administrativo"};
       if (!Security.validateSession(request, a)) {
            return mapping.findForward("errorPriv");
        }

        System.out.println("Paso Autenticación");

        String idObj = request.getParameter("id");


        ActionErrors errors = new ActionErrors();

        boolean data = ObjetoPerdido_DAO.eliminarObjetoPerdido(Long.parseLong(idObj));

        if (data == false) {
            errors.add("objeto_no_eliminado", new ActionMessage("errors.objeto_no_eliminado"));
            saveErrors(request, errors);
            return mapping.findForward(FAILURE);
        }


        errors.add("objeto_eliminado", new ActionMessage("errors.objeto_eliminado"));
        saveErrors(request, errors);

        return mapping.findForward(SUCCESS);

    }
}
